// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async(event, context) => {
  try {
    const result = await cloud.openapi.subscribeMessage.send({
      touser: event.openid, //要推送给那个用户
      data: {//推送的内容
        thing1: {
          value: event.habit
        },
        name4: {
          value: event.username
        },
        time3: {
          value: event.wartime
        },
        thing8: {
          value: '如果已经打卡，请忽略该消息！'
        }
      },
      templateId: 'uIfV2rNcN4zurV6A0PfU1nPIRX3ja2IIdx-3thfhM1E' //模板id
    })
    console.log(result)
    return result
  } catch (err) {
    console.log(err)
    return err
  }
}